package com.ruoyi.web.controller.rgpp;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.rgpp.domain.Jibencompany;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rgpp.domain.JmrJibencompany;
import com.ruoyi.rgpp.service.IJmrJibencompanyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 企业基本信息Controller
 *
 * @author ruoyi
 * @date 2022-06-13
 */
@Controller
@RequestMapping("/rgpp/jibencompany")
public class JmrJibencompanyController extends BaseController
{
    private String prefix = "rgpp/jibencompany";

    @Autowired
    private IJmrJibencompanyService jmrJibencompanyService;

    @RequiresPermissions("rgpp:jibencompany:view")
    @GetMapping()
    public String jibencompany()
    {
        return prefix + "/jibencompany";
    }

    /**
     * 查询企业基本信息列表
     */
    @RequiresPermissions("rgpp:jibencompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JmrJibencompany jmrJibencompany)
    {
        startPage();
        List<JmrJibencompany> list = jmrJibencompanyService.selectJmrJibencompanyList(jmrJibencompany);
        return getDataTable(list);
    }

    /**
     * 导出企业基本信息列表
     */
    @RequiresPermissions("rgpp:jibencompany:export")
    @Log(title = "企业基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmrJibencompany jmrJibencompany)
    {
        List<JmrJibencompany> list = jmrJibencompanyService.selectJmrJibencompanyList(jmrJibencompany);
        ExcelUtil<JmrJibencompany> util = new ExcelUtil<JmrJibencompany>(JmrJibencompany.class);
        return util.exportExcel(list, "企业基本信息数据");
    }

    /**
     * 导入企业基本信息列表
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JmrJibencompany> util = new ExcelUtil<JmrJibencompany>(JmrJibencompany.class);
        List<JmrJibencompany> JmrJibencompanyList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getLoginName();
        String message = jmrJibencompanyService.importJibencompany(JmrJibencompanyList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<JmrJibencompany> util = new ExcelUtil<JmrJibencompany>(JmrJibencompany.class);
        return util.importTemplateExcel("用户数据");
    }

    /**
     * 新增企业基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业基本信息
     */
    @RequiresPermissions("rgpp:jibencompany:add")
    @Log(title = "企业基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JmrJibencompany jmrJibencompany)
    {
        return toAjax(jmrJibencompanyService.insertJmrJibencompany(jmrJibencompany));
    }

    /**
     * 修改企业基本信息
     */
    @RequiresPermissions("rgpp:jibencompany:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JmrJibencompany jmrJibencompany = jmrJibencompanyService.selectJmrJibencompanyById(id);
        mmap.put("jmrJibencompany", jmrJibencompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业基本信息
     */
    @RequiresPermissions("rgpp:jibencompany:edit")
    @Log(title = "企业基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JmrJibencompany jmrJibencompany)
    {
        return toAjax(jmrJibencompanyService.updateJmrJibencompany(jmrJibencompany));
    }

    /**
     * 删除企业基本信息
     */
    @RequiresPermissions("rgpp:jibencompany:remove")
    @Log(title = "企业基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jmrJibencompanyService.deleteJmrJibencompanyByIds(ids));
    }
}
